package com.example.admin_oa.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.admin_oa.model.service.SysPermissionService;
import com.example.comment_oa.pojos.SysPermission;
import com.example.comment_oa.response.AjaxResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("adminOa/menu")
@CrossOrigin
public class MenuController {
    @Autowired
    StringRedisTemplate stringRedisTemplate;
    @Resource
    SysPermissionService sysPermissionService;

    @PostMapping("/getMenu")
    public AjaxResponse getMenu(){
        String user = stringRedisTemplate.opsForValue().get("user");
        JSONObject jsonObject = JSONObject.parseObject(user);
        List<SysPermission> meuList = sysPermissionService.meuList((int) jsonObject.get("userId"));
        return AjaxResponse.success(meuList);
    }

}
